<template>
	<view class="user">
		<!-- 顶部 -->
		<view class="user-header" style="background: url('/static/split-new/personal.png') no-repeat;background-size: 750upx 390upx;">

			<view class="hd-icon">
				<!-- 50 -->
				<image src="/static/split-new/message.png" mode="aspectFill" class="hd-message" @click="navTo('/pages/public/news')"></image>
				<image src="/static/split-new/setting.png" mode="aspectFill" class="hd-setting" @click="navTo('/pages/set/lph-set')"></image>

			</view>

			<view class="hd-content">
				<!-- 102 -->
				<view class="user-icon">
					<image :src="userInfo.shavatar" mode="aspectFill" v-if="isLogin"></image>
				</view>
				<text class="userName" v-if="isLogin">{{userInfo.nickname}}</text>
				<text class="userName" v-else @click.stop="navTo('/pages/public/userLogin')">未登陆</text>
				<view  class="hd-myStore" v-if="isLogin" @click="switchTabTo('/pages/myStore/myStore')">
					<text>我的店</text>
				</view>
				<!-- <text class="hd-myStore" v-if="isLogin" @click="switchTabTo('/pages/myStore/myStore')">我的店</text> -->
			</view>
		</view>
		<!-- nav部分 -->
		<view class="user-nav">
			
			<view class="nav-item" @click="navTo('/pages/public/collect')">
				<view class="item1" v-if="isLogin">
					{{userNum.collectCountNums}}
				</view>
				<view class="item1" v-else>
					**
				</view>
				<view class="item2 border-r" @click="navTo('/pages/public/collect')">
					收藏夹
				</view>

			</view>
			<view class="nav-item" @click="navTo('/pages/user/attention')">
				<view class="item1" v-if="isLogin">
					{{ userNum.attentionCountNums }}
				</view>
				<view class="item1" v-else>
					**
				</view>
				<view class="item2  border-r">
					关注店铺
				</view>
			</view>
			<view class="nav-item" @click="navTo('/pages/user/recentlyview')">
				<view class="item1" v-if="isLogin">
					{{ userNum.historyNums }}
				</view>
				<view class="item1" v-else>
					**
				</view>
				<view class="item2">
					最近浏览
				</view>
			</view>
		</view>

		<!--  assets 资产部分-->
		<view class="user-assets">

			<view class="at-line1">
				我的钱包
			</view>
			<view class="at-line2" v-if="isLogin">
				0.00
			</view>
			<view class="at-line2" v-else>
				0.00
			</view>
			<!-- <view class="at-line3" @click="navTo('/pages/myStore/withdraw')">
				提现
			</view> -->
		</view>
		<!-- 订单 -->
		<view class="user-order">
			<view class="od-title">
				<text class="text1">我的订单</text>
				<!-- <navigator url="../order/user-order"></navigator> -->
				<text class="text2" @click="switchTabTo('/pages/order/user-order',1)">查看全部订单</text>
				<text class="iconfont">&#xe600;</text>
			</view>
			<view class="od-content">
				<view class="od-item" @click="switchTabTo('/pages/order/user-order',4)">
					<!-- 58 -->
					<image src="/static/imgs/userImgs/icon_1.png" mode=""></image>
					<view>
						待自提
					</view>
				</view>
				<view class="od-item" @click="switchTabTo('/pages/order/user-order',2)">
					<image src="/static/imgs/userImgs/icon_2.png" mode=""></image>
					<view>
						待付款
					</view>
				</view>
				<view class="od-item" @click="switchTabTo('/pages/order/user-order',3)">
					<image src="/static/imgs/userImgs/icon_3.png" mode=""></image>
					<view>
						配送中
					</view>
				</view>
				<view class="od-item" @click="switchTabTo('/pages/order/user-order',5)">
					<image src="/static/imgs/userImgs/icon_4.png" mode=""></image>
					<view>
						已收货
					</view>
				</view>
				<view class="od-item" @click="navTo('/pages/user/assess')">
					<image src="/static/imgs/userImgs/icon_5.png" mode=""></image>
					<view>
						评价
					</view>
				</view>
				<view class="od-item" @click="navTo('/pages/afterSale/afterSale')">
					<image src="/static/imgs/userImgs/icon_6.png" mode=""></image>
					<view>
						退款/售后
					</view>
				</view>
				<view class="od-item" @click="navTo('/pages/set/suggestion')">
					<image src="/static/imgs/userImgs/icon_7.png" mode=""></image>
					<view>
						投诉/建议
					</view>
				</view>
				<view class="od-item" @click="navTo('/pages/fight/fight')">
					<image src="/static/imgs/userImgs/icon_8.png" mode=""></image>
					<view>
						我的团
					</view>
				</view>

			</view>
		</view>



	</view>
</template>

<script>
	import {
		mapState,
		mapMutations
	} from 'vuex';
	export default {
		data() {
			return {
				isLogin: false,
				userInfo: {},
				userNum: {}, // 收藏，关注的数量
				isClick: false
			};
		},
		
		onShow() {
			this.userInfo = uni.getStorageSync('lph-user-info');
			this.isLogin = false;
			// 判断是否登录
			let token = uni.getStorageSync('lph-token');
			if (token) {
				this.isLogin = true;
				
				this.getCollectCountNums();
				// this.getUserInfo(); // 此调用没用
				return
			}
			
		},
		computed: {
			// ...mapState(['isLogin','userInfo'])
		},
		
		methods: {
			// store 中的方法
			// ...mapMutations(['changeLogin','changeUserInfo']),
			async getUserInfo() {
				let a = await this.$http.getUserInfo();
				uni.stopPullDownRefresh();
			},
			async getCollectCountNums() { // 首页数量获取
				let a = await this.$http.getCollectCountNums();
				this.userNum = a.data;
			},
			switchTabTo(url, id) { // 到我的店
				if(this.isClick){ return }
				this.isClick = true
				if (!this.isLogin) {
					uni.showToast({
						title: '您还未登录',
						icon: 'none'
					})
					setTimeout(() => {
						this.isClick = false
						uni.navigateTo({
							url: '/pages/public/userLogin',
							animationType: 'slide-in-bottom'
						})
					}, 500);
					return
				} else {
					if (id) {
						uni.setStorageSync('user-orderId', id);
					}
					uni.switchTab({
						url: url
					});
				}
			},
			navTo(url) {
				if (this.isClick) { return }
				if (!this.isLogin) {
					this.isClick = true
					uni.showToast({
						title: '您还未登录',
						icon: 'none'
					})
					console.log(0)
					setTimeout(() => {
						this.isClick = false
						uni.navigateTo({
							url: '/pages/public/userLogin',
							animationType: 'slide-in-bottom'
						})
					}, 500);
					return
				}
				this.isClick = true
				uni.navigateTo({
					url: url
				});
			},

		},

		onPullDownRefresh() {
			this.getUserInfo();

			uni.showToast({
				title: '刷新成功',
				icon: 'none'
			});

		}

	}
</script>

<style lang="scss" scoped>
	@import 'static/css/user.scss';
	@import 'static/css/smallCommon.scss';
</style>
